package Workers;

import java.util.Hashtable;

import ServerSide.ClientHandling;
import ServerSide.ClientSock;

/**
 * @author Avishai Kopeliansky 
 * @ID 066717752
 * @author David Shimshon
 * @ID 038185617
 */
public class Dispatcher implements Runnable{
	private ClientHandling ch;
	private String s;

	/**
	 * @param ch ClientHandling rep for extracting the hashtable of authorized users
	 * @param msg the message to broadcast
	 */
	public Dispatcher(ClientHandling ch, String msg){
		this.ch = ch;
		this.s = msg;
	}
	@Override
	public void run() {
		Hashtable<String,ClientSock> hs = ch.getTable();
		//for each key exists in the keyset, dispatch the value the message requested
		for(String f : hs.keySet()){
			hs.get(f).sendMsg(s);
		}
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}



	}

}
